<?php

namespace App\Utils\Adapter;

use App\Utils\Adapter\Interfaces\MapAdapter;
use App\Utils\Thirdparty\Map\Amap;
use App\Utils\Thirdparty\Map\Wechat;
use App\Utils\Thirdparty\Map\BaiduMap;
class Map implements MapAdapter {

    //没有微信地图
    private $map;
    public function __construct(MapAdapter $mapAdapter)
    {
        $this->map = $mapAdapter;
    }

    /**
     * 适配器 ip定位
     * @param $ip
     * @return mixed|void
     * @throws \Exception
     */
    public function position($ip)
    {
        if ($this->map instanceof Amap) {

            return $this->map->position($ip);
        } elseif ($this->map instanceof Wechat) {

            return $this->map->position($ip);
        } elseif ($this->map instanceof BaiduMap) {

            return $this->map->position($ip);
        }
    }

    /**
     * 适配器 地理编码
     * @param $ip
     * @return mixed|void
     * @throws \Exception
     */
    public function getLocation($address)
    {
        if ($this->map instanceof Amap) {

            return $this->map->getLocation($address);
        } elseif ($this->map instanceof Wechat) {

            return $this->map->getLocation($address);
        } elseif ($this->map instanceof BaiduMap) {

            return $this->map->getLocation($address);
        }
    }


    /**
     * 适配器 步行导航
     * @param $ip
     * @return mixed|void
     * @throws \Exception
     */
    public function walkRouting($startPoint,$endPoint)
    {
        if ($this->map instanceof Amap) {

            return $this->map->walkRouting($startPoint,$endPoint);
        } elseif ($this->map instanceof Wechat) {

            return $this->map->walkRouting($startPoint,$endPoint);
        } elseif ($this->map instanceof BaiduMap) {

            return $this->map->walkRouting($startPoint,$endPoint);
        }
    }

    /**
     * 适配器 导航公交
     * @param $ip
     * @return mixed|void
     * @throws \Exception
     */
    public function busRouting($startPoint,$endPoint,$cityCode="")
    {
        if ($this->map instanceof Amap) {

            return $this->map->busRouting($startPoint,$endPoint,$cityCode);
        } elseif ($this->map instanceof Wechat) {

            return $this->map->busRouting($startPoint,$endPoint);
        } elseif ($this->map instanceof BaiduMap) {

            return $this->map->busRouting($startPoint,$endPoint);
        }
    }

    /**
     * 适配器 驾驶导航
     * @param $ip
     * @return mixed|void
     * @throws \Exception
     */
    public function drivingRouting($startPoint,$endPoint,$waypoints="")
    {
        if ($this->map instanceof Amap) {

            return $this->map->drivingRouting($startPoint,$endPoint);
        } elseif ($this->map instanceof Wechat) {

            return $this->map->drivingRouting($startPoint,$endPoint,$waypoints);
        } elseif ($this->map instanceof BaiduMap) {

            return $this->map->drivingRouting($startPoint,$endPoint);
        }
    }


    /**
     * 适配器 骑行导航
     * @param $ip
     * @return mixed|void
     * @throws \Exception
     */
    public function bicyclingRouting($startPoint,$endPoint)
    {
        if ($this->map instanceof Amap) {

            return $this->map->bicyclingRouting($startPoint,$endPoint);
        } elseif ($this->map instanceof Wechat) {

            return $this->map->bicyclingRouting($startPoint,$endPoint);
        } elseif ($this->map instanceof BaiduMap) {

            return $this->map->bicyclingRouting($startPoint,$endPoint);
        }
    }



    /**
     * 适配器 距离测量
     * @param $ip
     * @return mixed|void
     * @throws \Exception
     */
    public function distance($startPoint,$endPoint,$type="")
    {
        if ($this->map instanceof Amap) {

            return $this->map->distance($startPoint,$endPoint,$type);
        } elseif ($this->map instanceof Wechat) {

            return $this->map->distance($startPoint,$endPoint,$type);
        } elseif ($this->map instanceof BaiduMap) {

            return $this->map->distance($startPoint,$endPoint);
        }
    }


    /**
     * 适配器 划圈搜索
     * @param $ip
     * @return mixed|void
     * @throws \Exception
     */
    public function opi($startPoint,$endPoint,$radius,$type="")
    {
        if ($this->map instanceof Amap) {

            return $this->map->opi($startPoint,$endPoint,$radius,$type);
        } elseif ($this->map instanceof Wechat) {

            throw new \Exception('腾讯不能画圈');
        } elseif ($this->map instanceof BaiduMap) {

            throw new \Exception('百度不能画圈');
        }
    }

}
